<template>
    <div class="login">
        <div class="login-con">
            <el-card class="box-card">
                <div slot="header" class="clearfix" style="color:#fff;">欢迎登录</div>
                <el-form :model="form" ref="form" :rules="rules" label-width="80px" label-position="left" class="form-con" size="small">
                    <el-form-item label="用户名" prop="username">
                        <el-input v-model="form.username" ref="username" @keyup.enter.native="gogo"></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="password">
                        <el-input type="password" v-model="form.password" @keyup.enter.native="gogo" ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" size="medium" @click="submitForm('form')">登录</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
    name: 'login',
    data () {
        return {
            form: {
                username: '',
                password: '',
            },
			rules: {
				username: [
					{ required: true, message: '请输入账号', trigger: 'blur' },
				],
				password: [
					{ required: true, message: '请输入密码', trigger: 'blur' }
				]
			}
        }
    },

    components: {},

    computed: {},

    methods: {
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					this.$http({
						fun: 'login',
						username: this.form.username,
						password: this.form.password,
						requestType: 'get',
						cb: res => {
							console.log(res, '接口返回来的数据');
							let that = this
							if(res.accressToken){
								this.$message({
									message: '恭喜您，登录成功！',
									type: 'success'
								});
								setTimeout(function() {
                                    that.$router.push({
                                        name: 'dashboard',
                                    });
								},1000)
                            }else{
								this.$message({
									message: res.errmsg,
									type: 'warning'
								});
                            }
						},
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});



            // var para = {
            // 	fun : 'login',
            // 	username : this.form.username,
            // 	password : this.form.password,
            // 	requestType : 'get',
            // 	cb : res => {
            // 		console.log(res);

            // 		//已经登录过了。
            // 		// if(res == '1'){
            // 			this.$router.push({
            // 				name: 'dashboard',
            // 			});
            // 		// }
            // 	},
            // 	err : res => {
            // 		this.$notify.error({
            //           title: '错误',
            //           message: res,
            //         });
            // 	},
            // };
            // http(para);
        },
    },
    watch: {},
    mounted () {
        this.$refs['username'].focus()
    },
}
</script>

<style lang="less">
    @import './login.less';
    svg {
        width: 100px;
        height: 30px;
    }

</style>
